//
//  UseNavigationView.swift
//  learn-ios
//
//  Created by Dong on 2022/4/6.
//

import SwiftUI

struct UseNavigationView: View {
    var body: some View {
        VStack {
            // 创建导航视图
            NavigationView {
                
                // 创建导航链接
                List {
                    NavigationLink {
                        Text("New Page")
                    } label: {
                        Text("跳转至新页面")
                    }
                    // 设置导航页标题(仅可设置一次,多次设置无效)
                    .navigationTitle("导航页")

                    NavigationLink {
                        // 子导航页不需要声明导航视图（除非你需要视图嵌套）
                        NavigationLink {
                            Text("Page three")
                        } label: {
                            Text("Nav to page three")
                        }
                        .navigationTitle("page two")

                    } label: {
                        Text("跳转至带有二级跳转的视图")
                    }

                    NavigationLink {
                        Text("New Page")
                            .navigationTitle("New Page")
                            // 隐藏视图导航栏
                            .navigationBarHidden(true)

                    } label: {
                        Text("隐藏导航栏")
                    }
                    
                    NavigationLink{
                        Text("New Page")
                            .navigationBarBackButtonHidden(true)
                            .navigationTitle("New Page")
                    }label: {
                        Text("隐藏视图的导航栏后退按钮")
                    }
                    
                    NavigationLink{
                        Text("New Page")
                            .navigationTitle("New Page")
                    }label: {
                        Text("导航栏顶部视图")
                    }
                    
                    NavigationLink{
                        ReturnLastNav()
                    }label: {
                        Text("手动返回上一级")
                    }
                }
                .listStyle(.inset)
            }
            .navigationViewStyle(.columns)
        }
    }
}

struct UseNavigationView_Previews: PreviewProvider {
    static var previews: some View {
        UseNavigationView()
    }
}
